package horncomb.bpm.process.def.activity;

import java.util.List;

import horncomb.bpm.process.core.ExecutionContext;
import horncomb.bpm.process.core.Transition;
import horncomb.bpm.process.def.Action;

/**
 * @author Daniel
 */
public class SimpleActivityDefinition extends AbstractActivityDefinition {
	private static final long serialVersionUID = 1503294032588458717L;
	private Action action = null;

	/**
	 * @param id
	 */
	public SimpleActivityDefinition(String id) {
		super(id);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void doEnter(ExecutionContext context) {
		super.doEnter(context);
		// TODO separate to a abstract strategy
		if (this.hasLeavingTransitions()) {
			// only one transition
			List<Transition> transitions = this.getLeavingTransitions();
			if (transitions.size() == 1) {
				context.setTransition(transitions.get(0));
			}
		}
	}

	protected void doEnteringAction(ExecutionContext context) {
		if (this.action != null) {
			this.action.execute(context);
		}
	}

	/**
	 * @param actionChain
	 *            the actionChain to set
	 */
	public void setAction(Action action) {
		this.action = action;
	}
}
